#include "CButton.h"

CButton::CButton() {
  m_hButton = NULL;
}

void CButton::SetHandle(HWND hButton) {
  m_hButton = hButton;
}

HWND CButton::GetHandle() {
  return m_hButton;
}

HWND CButton::Create(LPCTSTR lpszCaption, DWORD dwStyle, int x, int y, int w,
    int h, UINT nCtrlID, HWND hParentWnd) {
  m_hButton = ::CreateWindow("BUTTON", lpszCaption, WS_VISIBLE | WS_CHILD |
      dwStyle, x, y, w, h, hParentWnd, (HMENU)(long long)nCtrlID, NULL, NULL);

  return m_hButton;
}

BOOL CButton::Destroy() {
  return ::DestroyWindow(m_hButton);
}

void CButton::Click() {
  ::SendMessage(m_hButton, BM_CLICK, 0, 0);
}

void CButton::SetState(BOOL bHighlight) {
  ::SendMessage(m_hButton, BM_SETSTATE, bHighlight, 0);
}

UINT CButton::GetState() {
  return ::SendMessage(m_hButton, BM_GETSTATE, 0, 0);
}

void CButton::SetCheck(int nCheck) {
  ::SendMessage(m_hButton, BM_SETCHECK, nCheck, 0);
}

UINT CButton::GetCheck() {
  return ::SendMessage(m_hButton, BM_GETCHECK, 0, 0);
}

void CButton::SetStyle(DWORD dwStyle, BOOL bRedraw) {
  ::SendMessage(m_hButton, BM_SETSTYLE, dwStyle, MAKELPARAM(bRedraw, 0));
}

UINT CButton::GetStyle() {
  return GetWindowLong(m_hButton, GWL_STYLE) & BS_TYPEMASK;
}

void CButton::SetDontClick(BOOL bState) {
  ::SendMessage(m_hButton, BM_SETDONTCLICK, bState, 0);
}

